/*     */ package dm.jdbc.util;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class EscapeTokenizer
/*     */ {
/*  25 */   private String source = null;
/*     */   
/*  27 */   private boolean emittingEscapeCode = false;
/*     */   
/*  29 */   private boolean inComment = false;
/*     */   
/*  31 */   private boolean inQuotes = false;
/*     */   
/*  33 */   private char lastChar = '\000';
/*     */   
/*  35 */   private char lastLastChar = '\000';
/*     */   
/*  37 */   private char quoteChar = '\000';
/*     */   
/*  39 */   private int bracesLevel = 0;
/*     */   
/*  41 */   private int pos = 0;
/*     */   
/*  43 */   private int sourceLength = 0;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public EscapeTokenizer(String s)
/*     */   {
/*  55 */     this.source = s;
/*  56 */     this.sourceLength = s.length();
/*  57 */     this.pos = 0;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public synchronized boolean hasMoreTokens()
/*     */   {
/*  69 */     return this.pos < this.sourceLength;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public synchronized String nextToken()
/*     */   {
/*  78 */     StringBuffer tokenBuf = new StringBuffer(this.sourceLength);
/*     */     
/*  80 */     if (this.emittingEscapeCode) {
/*  81 */       tokenBuf.append("{");
/*  82 */       this.emittingEscapeCode = false;
/*     */     }
/*  85 */     for (; 
/*  85 */         this.pos < this.sourceLength; this.pos += 1) {
/*  86 */       char c = this.source.charAt(this.pos);
/*     */       
/*  88 */       if (c == '\'') {
/*  89 */         if (this.lastChar != '\\') {
/*  90 */           if (this.inQuotes) {
/*  91 */             if (this.quoteChar == c) {
/*  92 */               this.inQuotes = false;
/*     */             }
/*     */           } else {
/*  95 */             this.inQuotes = true;
/*  96 */             this.quoteChar = c;
/*     */           }
/*  98 */         } else if (this.lastLastChar == '\\') {
/*  99 */           if (this.inQuotes) {
/* 100 */             if (this.quoteChar == c) {
/* 101 */               this.inQuotes = false;
/*     */             }
/*     */           } else {
/* 104 */             this.inQuotes = true;
/* 105 */             this.quoteChar = c;
/*     */           }
/*     */         }
/*     */         
/* 109 */         tokenBuf.append(c);
/* 110 */       } else if (c == '"') {
/* 111 */         if ((this.lastChar != '\\') && (this.lastChar != '"')) {
/* 112 */           if (this.inQuotes) {
/* 113 */             if (this.quoteChar == c) {
/* 114 */               this.inQuotes = false;
/*     */             }
/*     */           } else {
/* 117 */             this.inQuotes = true;
/* 118 */             this.quoteChar = c;
/*     */           }
/* 120 */         } else if (this.lastLastChar == '\\') {
/* 121 */           if (this.inQuotes) {
/* 122 */             if (this.quoteChar == c) {
/* 123 */               this.inQuotes = false;
/*     */             }
/*     */           } else {
/* 126 */             this.inQuotes = true;
/* 127 */             this.quoteChar = c;
/*     */           }
/*     */         }
/*     */         
/* 131 */         tokenBuf.append(c);
/* 132 */       } else if (c == '-') {
/* 133 */         if (this.lastChar == '-') { if (((this.lastLastChar != '\\' ? 1 : 0) & (this.inQuotes ? 0 : 1)) != 0) {
/* 134 */             this.inComment = true;
/*     */           }
/*     */         }
/* 137 */         tokenBuf.append(c);
/* 138 */       } else if ((c == '\n') || (c == '\r')) {
/* 139 */         this.inComment = false;
/*     */         
/* 141 */         tokenBuf.append(c);
/* 142 */       } else if (c == '{') {
/* 143 */         if ((this.inQuotes) || (this.inComment)) {
/* 144 */           tokenBuf.append(c);
/*     */         } else {
/* 146 */           this.bracesLevel += 1;
/*     */           
/* 148 */           if (this.bracesLevel == 1) {
/* 149 */             this.pos += 1;
/* 150 */             this.emittingEscapeCode = true;
/*     */             
/* 152 */             return tokenBuf.toString();
/*     */           }
/* 154 */           tokenBuf.append(c);
/*     */         }
/*     */       }
/* 157 */       else if (c == '}') {
/* 158 */         tokenBuf.append(c);
/*     */         
/* 160 */         if ((!this.inQuotes) && (!this.inComment)) {
/* 161 */           this.lastChar = c;
/*     */           
/* 163 */           this.bracesLevel -= 1;
/*     */           
/* 165 */           if (this.bracesLevel == 0) {
/* 166 */             this.pos += 1;
/*     */             
/* 168 */             return tokenBuf.toString();
/*     */           }
/*     */         }
/*     */       } else {
/* 172 */         tokenBuf.append(c);
/*     */       }
/*     */       
/* 175 */       this.lastLastChar = this.lastChar;
/* 176 */       this.lastChar = c;
/*     */     }
/*     */     
/* 179 */     return tokenBuf.toString();
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\util\EscapeTokenizer.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */